﻿CREATE PROCEDURE [dbo].[RunInsert]
(@RunID UniqueIdentifier,
@WorkflowID UniqueIdentifier,
@SubmitTime datetime,
@ReceiveTime datetime,
@StartTime datetime,
@FinishTime datetime,
@Vars varchar(max))
AS begin 
	if exists (select * from Run where RunID=@RunID) begin
		update Run set 
			WorkflowID=@WorkflowID,
			SubmitTime=@SubmitTime,
			ReceiveTime=@ReceiveTime,
			StartTime=@StartTime,
			FinishTime=@FinishTime,
			Vars=@Vars
		where
			RunID=@RunID;
	end
	else begin
		insert into Run (
			RunID,
			WorkflowID,
			SubmitTime,
			ReceiveTime,
			StartTime,
			FinishTime,
			Vars) 
		values (
			@RunID,
			@WorkflowID,
			@SubmitTime,
			@ReceiveTime,
			@StartTime,
			@FinishTime,
			@Vars);
	end
end